package com.gs.disk.dao.admin;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gs.common.mapper.CommonMapper;

import com.gs.disk.dto.admin.RoleDto;
import com.gs.entity.RoleEntity;
import org.apache.ibatis.annotations.Mapper;

import java.io.Serializable;
import java.util.*;

/**
 * @title: 孙杨申
 * @date 2022/2/22 20:26
 */
@Mapper
public interface RoleDao extends CommonMapper<RoleEntity, RoleDto> {

    /**
     * 根据角色id列表获取
     * @param ids 角色id
     * @return
     */
    default List<String> getMenuList(Serializable[] ids) {
        List<String> menuList = new LinkedList<>();
        QueryWrapper<RoleEntity> wrapper = new QueryWrapper<>();
        for (Serializable id : ids) {
            wrapper.eq("id", id);
            wrapper.or();
        }
        List<RoleEntity> roleEntities = selectList(wrapper);
        roleEntities.forEach(r -> {
            String menuListStr = r.getMenuList();
            if(ObjectUtil.isNotEmpty(menuListStr)) {
                String[] split = menuListStr.split(",");
                for (String s : split) {
                    menuList.add(s);
                }
            }
        });
        return menuList;
    }

}